//
//  PageFlowMenuTableViewCell_OneHalfPage.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2020/10/7.
//  Copyright © 2020 moon. All rights reserved.
//

#import "PageFlowMenuTableViewCell_OneHalfPage.h"

@implementation PageFlowMenuTableViewCell_OneHalfPage

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.pageFlowLayout.pagingEnabled = YES;
        self.pageFlowLayout.pagingCellPosition = 0.2;
        self.pageFlowLayout.pagingBoundsPosition = 0.1;
        self.pageFlowLayout.interitemSpacing = 10;
        self.pageFlowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, self.pageFlowLayout.interitemSpacing);
        self.pageFlowLayout.enableCycleScroll = YES;
        self.collectionView.model.forwardDelegate = self;
        MKUILayoutConstraintItemWrapper *w1 = [MKUILayoutConstraintItemWrapper wrapItem:self.collectionView sizeThatFitsBlock:^CGSize(MKUILayoutConstraintItemWrapper * _Nonnull wrapper, CGSize size, BOOL resizeItems) {
            return CGSizeMake(size.width, 80);
        }];
        //
        self.flowlayout = [[MKUIFlowLayoutConstraint alloc] initWithItems:@[w1,self.pageControl] constraintParam:(MKUIFlowLayoutConstraintParam_V_C_C) contentInsets:UIEdgeInsetsZero interitemSpacing:5];
    }
    return self;
}
- (void)layoutMyContentView{
    [super layoutMyContentView];
    CGRect bounds = self.myContentView.bounds;
    self.flowlayout.bounds = bounds;
    [self.flowlayout layoutItemsWithResizeItems:YES];
}
- (CGSize)sizeMyContentViewThatFits:(CGSize)size{
    return [self.flowlayout sizeThatFits:size resizeItems:YES];
}
+ (CGFloat)pagingBoundsPositionWidth{
    return 100;
}
- (CGSize)collectionView:(UICollectionView *)collectionView pageFlowLayout:(MKUICollectionViewPageFlowLayout *)collectionViewLayout itemSizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGRect bounds = collectionView.bounds;
    CGSize size = bounds.size;
    size.width = 50;
    return size;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView pageFlowLayout:(MKUICollectionViewPageFlowLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    UIEdgeInsets insets = UIEdgeInsetsZero;
    insets.left = self.class.pagingBoundsPositionWidth;
    return insets;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView pageFlowLayout:(MKUICollectionViewPageFlowLayout *)collectionViewLayout interitemSpacingForSectionAtIndex:(NSInteger)section{
    CGFloat interitemSpacing = 20;
    return interitemSpacing;
}
- (CGFloat)pagingBoundsPositionForCollectionView:(UICollectionView *)collectionView pageFlowLayout:(MKUICollectionViewPageFlowLayout *)collectionViewLayout{
    CGRect bounds = collectionView.bounds;
    CGFloat pagingBoundsPosition = self.class.pagingBoundsPositionWidth/bounds.size.width;
    return pagingBoundsPosition;
}
@end
